# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=pyinstaller
pkgver=6.17.0
pkgrel=1
epoch=2
groups=('blackarch' 'blackarch-misc')
pkgdesc='Bundles a Python application and all its dependencies into a single package.'
arch=('x86_64' 'aarch64')
url='https://pyinstaller.org'
license=('Apache-2.0' 'GPL-2.0-or-later' 'MIT')
depends=(
  'python' 'python-setuptools' 'python-altgraph' 'pyinstaller-hooks-contrib' # project python dependencies
  'glibc' 'binutils' 'gcc' 'base-devel' # project system dependencies
)
makedepends=(
  'python-build' 'python-pip' 'python-wheel' # python package
  'waf' # bootloader
)
source=("https://files.pythonhosted.org/packages/source/${pkgname::1}/$pkgname/$pkgname-$pkgver.tar.gz"
        'fortify-source-fix.patch')
sha512sums=('e186827ebf261c02dddd590d073b8eca310fb62069dc3e5bdde7618b8247114fded3e88831a577a964c482d9122d13f1097c4147978b9c05c388b77920b67a2f'
            '765a2f0c984d966c27309194e73a50b325309c5e65253c92a7140d8b179f94394dd0e01aa1b46b3777a1a06da33ce92919070dd70fde87bf5d81eb750d73f5ed')
options=('!strip' '!emptydirs')

prepare() {
  cd "$pkgname-$pkgver"

  # Remove pre-built binaries
  rm -rf PyInstaller/bootloader/{Darwin,Linux,Windows}*

  # Avoid redefining _FORTIFY_SOURCE if default makepkg CFLAGS are used
  patch -Np1 -i "${srcdir}/fortify-source-fix.patch"
}

build() {
  cd "$pkgname-$pkgver"

  # Compile bootloader
  #cd bootloader
  #python ./waf all
  #cd ..

  # Build package
  python -m build --wheel --outdir="$startdir/dist"
}

package() {
  cd "$pkgname-$pkgver"

  # Package
  pip install \
    --verbose \
    --disable-pip-version-check \
    --no-warn-script-location \
    --ignore-installed \
    --no-compile \
    --no-deps \
    --root="$pkgdir" \
    --prefix=/usr \
    --no-index \
    --find-links="file://$startdir/dist" \
    $pkgname

  # Man pages
  install -Dm 644 doc/{"$pkgname",pyi-makespec}.1 -t \
    "$pkgdir/usr/share/man/man1/"

  # Custom license
  install -Dm 644 COPYING.txt -t "$pkgdir/usr/share/licenses/$pkgname/"
}

